package servlets;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONObject;

import jmysql.CPersonal;

/**
 * Servlet implementation class CConsultaPersonal
 */
@WebServlet("/CConsultaPersonal")
public class CConsultaPersonal extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public CConsultaPersonal() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request,response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		String tipo=request.getParameter("tipo");
		CPersonal cp=new CPersonal();
		JSONObject j=new JSONObject();
		
		if(tipo.equalsIgnoreCase("ListaPersonal"))
			j=cp.GetListaPersonal();
		
		if(tipo.equalsIgnoreCase("ListaPersonalDescargar"))
			j=cp.GetListaPersonalDescargar();
			
		/*
		else if(tipo.equalsIgnoreCase("Modificar")){
			int estado=Integer.parseInt(request.getParameter("estado"));
			int nopersonal=Integer.parseInt(request.getParameter("nopersonal"));
			cp.UpdateEstado(nopersonal, estado);
		}*/
		
		else if(tipo.equalsIgnoreCase("Eliminar")){
			int nopersonal=Integer.parseInt(request.getParameter("nopersonal"));
			cp.Eliminar(nopersonal);
		}
		
		response.setContentType("application/json"); 
		PrintWriter out=response.getWriter();
		out.print(j);
		out.close();
	}

}
